import Vue from 'vue'
import store from '../store/index.js'
/**权限指令**/
 Vue.directive('has', {
    inserted (el, binding) {
        // 当前按钮传递的值( v-permission="'add'" 中的值)
        const currentTag = binding.value.action
        const effect = binding.value.effect
        // 获取到存放在 store 中的权限数据
        // console.log('store.getters.permissions',store.getters.permissions)
        const currentRight = store.getters.permissions
        // 判断是否存在对应的按钮权限+
        let item = currentRight.filter((item) => {
          return item === currentTag
        })
        //不具备权限则删除（隐藏）或者禁用该按钮 (el.parentNode 获取当前节点的父节点),根据在芫荽绑定的值去决定
        if (item.length === 0) {
          if (effect === 'disabled') {
            el.disabled = true
            el.classList.add('is-disabled')
          }else if(effect ==='noPremiss'){
            el.style.display = 'block'
          }else if(effect ==='hide'){
            el.style.display = 'none'
          }else {
            // el.disabled = true
            // el.classList.add('is-disabled')
          }
        }
      }
  });
  // 权限检查方法
//   Vue.prototype.$_has = function (value) {
//     let isExist = false;
//     // 获取用户按钮权限
//     let btnPermissionsStr = store.getters.permissions
    
//     if (btnPermissionsStr == undefined || btnPermissionsStr == null) {
//         return false;
//     }
//     console.log('btnPermissionsStr--',btnPermissionsStr)
//     console.log('btnPermissionsStr',value.indexOf(btnPermissionsStr))
//     if (value.indexOf(btnPermissionsStr) > -1) {
//         isExist = true;
//     }
//     return isExist;
//   };
//   export default has